#include "fileiconprovider.h"
#include <QFileIconProvider>
#include <QDebug>

FileIconProvider::FileIconProvider() :
    QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
{

    mIconsMap["jpg"] = "image-jpeg";
    mIconsMap["gif"] = "image-gif";
    mIconsMap["png"] = "image-png";
    mIconsMap["bmp"] = "image-bmp";
    mIconsMap["jpeg"] = "image-jpeg";
    mIconsMap["tiff"] = "image-tiff";
    mIconsMap["svg"] = "image-svg";
    mIconsMap["psd"] = "psd";
    mIconsMap["thm"] = "image";
    mIconsMap["tif"] = "image";
    mIconsMap["pspimage"] = "image";
    mIconsMap["jpeg"] = "image";
    mIconsMap["tiff"] = "image";
    mIconsMap["ai"] = "image-svg";
    mIconsMap["drw"] = "image-svg";
    mIconsMap["eps"] = "image-svg";
    mIconsMap["ps"] = "image-svg";


    mIconsMap["wav"] = "audio-wav";
    mIconsMap["ogg"] = "audio-ogg";
    mIconsMap["wma"] = "audio-wma";
    mIconsMap["mp3"] = "audio-mp3";
    mIconsMap["au"]  = "image-jpeg";
    mIconsMap["snd"] = "audio";
    mIconsMap["aif"] = "audio";
    mIconsMap["iff"] = "audio";
    mIconsMap["aifc"]= "audio";
    mIconsMap["aiff"]= "audio";
    mIconsMap["m3u"] = "audio-pl";
    mIconsMap["ra"]  = "audio";
    mIconsMap["ram"] = "audio";

    mIconsMap["mpeg"]= "video";
    mIconsMap["mpg"] = "video";
    mIconsMap["mov"] = "video";
    mIconsMap["mp3"] = "video";
    mIconsMap["asf"] = "video";
    mIconsMap["asx"] = "video";
    mIconsMap["avi"] = "video";
    mIconsMap["asr"] = "video";
    mIconsMap["mpv2"]= "video";
    mIconsMap["mpe"] = "video";
    mIconsMap["mpa"] = "video";
    mIconsMap["3g2"]= "video";
    mIconsMap["3gp"] = "video";
    mIconsMap["mp4"] = "video";
    mIconsMap["swf"] = "video";
    mIconsMap["vob"] = "video";
    mIconsMap["wmv"] = "video";

    mIconsMap["doc"]= "document-doc";
    mIconsMap["docx"] = "document-doc";
    mIconsMap["log"] = "document-text";
    mIconsMap["msg"] = "document-text";
    mIconsMap["pages"] = "document-text";
    mIconsMap["rtf"] = "document";
    mIconsMap["txt"] = "document-text";
    mIconsMap["wpd"] = "document-doc";
    mIconsMap["wps"]= "document-doc";
    mIconsMap["pdf"]= "pdf";

    mIconsMap["csv"]= "xls";
    mIconsMap["dat"] = "xls";
    mIconsMap["xls"] = "xls";
    mIconsMap["xlsx"] = "xls";
    mIconsMap["wks"] = "xls";
    mIconsMap["efx"] = "document-text";
    mIconsMap["key"] = "ppt";
    mIconsMap["pps"] = "ppt";
    mIconsMap["ppt"] = "ppt";
    mIconsMap["pptx"] = "ppt";
    mIconsMap["vcf"]= "vcf";
    mIconsMap["xml"]= "xml";

    mIconsMap["accdb"] = "data";
    mIconsMap["db"] = "data";
    mIconsMap["dbf"] = "data";
    mIconsMap["mdb"]= "data";
    mIconsMap["pdb"]= "data";
    mIconsMap["sql"]= "data";

    mIconsMap["app"]= "bin";
    mIconsMap["bat"] = "bin";
    mIconsMap["cgi"] = "bin";
    mIconsMap["com"] = "bin";
    mIconsMap["exe"] = "bin-exe";
    mIconsMap["gadget"] = "bin";
    mIconsMap["jar"] = "bin-jar";
    mIconsMap["pif"] = "bin";
    mIconsMap["wsf"] = "bin";
    mIconsMap["sh"] = "bin";

    mIconsMap["asp"]= "script";
    mIconsMap["cer"] = "script";
    mIconsMap["csr"] = "script";
    mIconsMap["css"] = "css";
    mIconsMap["htm"] = "bin-exe";
    mIconsMap["html"] = "html";
    mIconsMap["js"] = "js";
    mIconsMap["jsp"] = "js";
    mIconsMap["php"] = "php";
    mIconsMap["rss"] = "rss";
    mIconsMap["xhtml"] = "html";


    mIconsMap["fnt"] = "font";
    mIconsMap["fon"] = "font";
    mIconsMap["otf"] = "font";
    mIconsMap["ttf"] = "font";


    mIconsMap["7z"]= "script";
    mIconsMap["deb"] = "deb";
    mIconsMap["gz"] = "tar";
    mIconsMap["tgz"] = "tar";
    mIconsMap["pkg"] = "compress";
    mIconsMap["rar"] = "rar";
    mIconsMap["sit"] = "compress";
    mIconsMap["sitx"] = "compress";
    mIconsMap["zip"] = "zip";
    mIconsMap["zipx"] = "zip";

    mIconsMap["dmg"]= "iso";
    mIconsMap["iso"] = "iso";
    mIconsMap["toast"] = "iso";
    mIconsMap["vcd"] = "iso";

    mIconsMap["c"]= "c";
    mIconsMap["cpp"] = "cpp";
    mIconsMap["class"] = "tar";
    mIconsMap["cs"] = "c";
    mIconsMap["dtd"] = "c";
    mIconsMap["fla"] = "fla";
    mIconsMap["m"] = "script";
    mIconsMap["pl"] = "py";
    mIconsMap["py"] = "py";

    mIconsMap["msi"]= "bin-exe";
    mIconsMap["part"] = "cpp";







}

QPixmap FileIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{

    qDebug()<<"ID ="<<id;

    QFileInfo info(id);


    QString fileName = mIconsMap.value(info.suffix().toLower(),"empty");

    if (!info.suffix().isEmpty())
        return QPixmap (":"+fileName+".png");
    else return QPixmap (":folder.png");


    //    return model->fileIcon(model->index(0,0)).pixmap(32,32);


}
